/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb.system;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author ciummo
 */
@Stateless
public class SessioneFacade extends AbstractFacade<Sessione> implements SessioneFacadeRemote {
    @PersistenceContext(unitName = "DGestEJBSeverPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public SessioneFacade() {
        super(Sessione.class);
    }
    
    
    public Sessione findSessione (String username){

        Sessione s = null;

        try {
            
            String sql = "SELECT s FROM Sessione s WHERE s.username = :username";
            Query query = em.createQuery(sql);
            query.setParameter("username", username);

            s = ((Sessione) query.getResultList().get(0));
        }
        catch (Exception ex) {
            return s;
        }
     return s;
    }
    
}
